#define BTN_UP 1
#define BTN_DOWN 0

#define SPEED_INCREAMENT 0.5


SpeedAction ReadButton() {
  int lev_up  = digitalRead(PIN_SPEED_UP);
  int lev_down = digitalRead(PIN_SPEED_DOWN);

  if (BTN_UP == lev_up && BTN_UP == lev_down) {
    return SPEED_STAY;
  }
  else if (BTN_DOWN == lev_up && BTN_UP == lev_down) {
    return SPEED_UP;
  }
  else if(BTN_UP == lev_up && BTN_DOWN == lev_down) {
    return SPEED_DOWN;
  }
  else {
    return SPEED_CONFIRM;
  }
}


void DoBtnAction(SpeedAction action) {
  switch (action) {
    case SPEED_UP:
      g_speed_tar_ctrl += SPEED_INCREAMENT;
      break;
    case SPEED_DOWN:
      g_speed_tar_ctrl -= SPEED_INCREAMENT;
      break;
    case SPEED_CONFIRM:
      write_i2c(true);
  }
}
